From 678aa8088f6b7a860b874740f839d100991fdd8c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 14 May 2019 22:23:15 +0200 Subject: [PATCH] rgba: Add GDK_RGBA() macro So far it's private, but it's a pretty cute way to use hex colors, so we might conside making it public. --- gdk/gdkrgbaprivate.h | 11 +++++++++++ gsk/gskrendernodeparser.c | 10 +++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gdk/gdkrgbaprivate.h b/gdk/gdkrgbaprivate.h index 58470e04c9..5126f57355 100644 --- a/gdk/gdkrgbaprivate.h +++ b/gdk/gdkrgbaprivate.h @@ -24,6 +24,17 @@ #include "gtk/css/gtkcssparserprivate.h" +#define _GDK_RGBA_DECODE(c) ((unsigned)(((c) >= 'A' && (c) <= 'F') ? ((c)-'A'+10) : \ + ((c) >= 'a' && (c) <= 'f') ? ((c)-'a'+10) : \ + ((c) >= '0' && (c) <= '9') ? ((c)-'0') : \ + -1)) +#define _GDK_RGBA_SELECT_COLOR(_str, index3, index6) _GDK_RGBA_DECODE (sizeof(_str) <= 4 ? (_str)[index3] : (_str)[index6]) +#define GDK_RGBA(str) ((GdkRGBA) {\ + ((_GDK_RGBA_SELECT_COLOR(str, 0, 0) << 4) | _GDK_RGBA_SELECT_COLOR(str, 0, 1)) / 255., \ + ((_GDK_RGBA_SELECT_COLOR(str, 1, 2) << 4) | _GDK_RGBA_SELECT_COLOR(str, 1, 3)) / 255., \ + ((_GDK_RGBA_SELECT_COLOR(str, 2, 4) << 4) | _GDK_RGBA_SELECT_COLOR(str, 2, 5)) / 255., \ + ((sizeof(str) % 4 == 1) ? ((_GDK_RGBA_SELECT_COLOR(str, 3, 6) << 4) | _GDK_RGBA_SELECT_COLOR(str, 3, 7)) : 0xFF) / 255 }) + gboolean gdk_rgba_parser_parse (GtkCssParser *parser, GdkRGBA *rgba); diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c index 07e55fd7a2..b6832347c2 100644 --- a/gsk/gskrendernodeparser.c +++ b/gsk/gskrendernodeparser.c @@ -688,7 +688,7 @@ static GskRenderNode * parse_color_node (GtkCssParser *parser) { graphene_rect_t bounds = GRAPHENE_RECT_INIT (0, 0, 0, 0); - GdkRGBA color = { 0, 0, 0, 1 }; + GdkRGBA color = GDK_RGBA("FF0000"); const Declaration declarations[] = { { "bounds", parse_rect, NULL, &bounds }, { "color", parse_color, NULL, &color }, @@ -732,7 +732,7 @@ static GskRenderNode * parse_inset_shadow_node (GtkCssParser *parser) { GskRoundedRect outline = GSK_ROUNDED_RECT_INIT (0, 0, 0, 0); - GdkRGBA color = { 0, 0, 0, 1 }; + GdkRGBA color = GDK_RGBA("000000"); double dx = 1, dy = 1, blur = 0, spread = 0; const Declaration declarations[] = { { "outline", parse_rounded_rect, NULL, &outline }, @@ -753,7 +753,7 @@ parse_border_node (GtkCssParser *parser) { GskRoundedRect outline = GSK_ROUNDED_RECT_INIT (0, 0, 0, 0); float widths[4] = { 1, 1, 1, 1 }; - GdkRGBA colors[4] = { { 0, 0, 0, 1 }, {0, 0, 0, 1 }, {0, 0, 0, 1 }, { 0, 0, 0, 1 } }; + GdkRGBA colors[4] = { GDK_RGBA("000"), GDK_RGBA("000"), GDK_RGBA("000"), GDK_RGBA("000") }; const Declaration declarations[] = { { "outline", parse_rounded_rect, NULL, &outline }, { "widths", parse_float4, NULL, &widths }, @@ -794,7 +794,7 @@ static GskRenderNode * parse_outset_shadow_node (GtkCssParser *parser) { GskRoundedRect outline = GSK_ROUNDED_RECT_INIT (0, 0, 0, 0); - GdkRGBA color = { 0, 0, 0, 1 }; + GdkRGBA color = GDK_RGBA("000000"); double dx = 1, dy = 1, blur = 0, spread = 0; const Declaration declarations[] = { { "outline", parse_rounded_rect, NULL, &outline }, @@ -1005,7 +1005,7 @@ parse_text_node (GtkCssParser *parser) { PangoFont *font = NULL; graphene_point_t offset = GRAPHENE_POINT_INIT (0, 0); - GdkRGBA color = { 0, 0, 0, 1 }; + GdkRGBA color = GDK_RGBA("000000"); PangoGlyphString *glyphs = NULL; const Declaration declarations[] = { { "font", parse_font, clear_font, &font }, -- 2.30.2